<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
  <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script type="text/javascript">
	//保存服务
	var  branId="${branId}";
	function  saveService(id){
		$("#status").val(id);
		var message;
		//保存不做处理
		if(id==1){
			if(!checkForm1()){
				 return;
			}
			message="你确定要保存吗?";
		}else{
			if(!checkForm()){
				 return;
			}
			message="你确定要提交吗?"; 
		}
		$.messager.confirm('温馨提示', message, function(flag) {
			if (flag) {
				$("#hide_loading").show();
				$.ajax({
					url:"${basePath}filemanagement/customer/saveApplyCustomer.shtml",
					dataType:"json",
					type:"post",
					async:false,
					data:$("#saveService").serialize(),
					error : function(XMLHttpRequest) {
			 				ajaxError(XMLHttpRequest);
			 		},
					success:function(result){
						 if(result=="1"){
							 $("#hide_loading").hide();
							 window.location.href="${basePath}filemanagement/customer/serviceList.shtml";
						 }
					}
				});
			}
		});
	}
	function checkIsTel(thisObj){
		 var value=$(thisObj).val();
		 var regexp=/^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
		 if(!checkIsNull(value)){
			  if(!regexp.test(value)){
				   alertWarning("请输入正确的固话号码");
				   $(thisObj).val("");
			   }
		 }
	}
	function checkIsMobile(thisObj){
		 var value=$(thisObj).val();
		  var reg=/1[3,4,5,8][0-9]{9}$/;
		  if(!checkIsNull(value)){
			  if(!reg.test(value)){
				   alertWarning("请输入正确的手机号码!");
				   $(thisObj).val("");
			   }
		  }
	}
	function checkForm1(){
		var  cusName=$("#cusName").val();
		if(checkIsNull(cusName)){
			alertWarning("姓名不能为空!");
			return false;
		}
		return true;
	}
	 function checkIsNull(val){
		  if(val==""||$.trim(val)==""){
				return true;		  
		  }
		  return false;
	  }
	 
		function checkForm(){
			
			var  cusName=$("#cusName").val();
			if(checkIsNull(cusName)){
				alertWarning("姓名不能为空!");
				return false;
			}
			var  comments=$("#comments").val();
			if(checkIsNull(comments)){
				alertWarning("备注不能为空!");
				return false;
			}
			var mobile=$("#mobile").val();
			if(checkIsNull(mobile)){
				alertWarning("手机不能为空!");
				return  false;
			}
			var  hand=	$("#handleId").val();
			if(checkIsNull(hand)){
				alertWarning("请选择服务的处理人!");
				return false;
			}
			return true;
		}
		//得到选中的id值.
		function getSelectVal(){
			var selectObj=$("input:[name='vipId']:checked");
			$("#fkMemId").val(selectObj.val());
			$("#cusName").val(selectObj.attr("cusName"));
			$("#selectVip").window('close');
		}
	//设定处理人
	function setHandleUser(){
		$("#x").window('close');
		var  obj=$("input:[name='pkUsrId']:checked");
		var  objVal=$(obj).val();
		var userNames=$(obj).attr("userNames");
		var jobs=$(obj).attr("jobs");
		var html="<tr><th>姓名</th><th>职位</th><th>操作</th></tr>";
		html+="<tr id='delFlag'><td>"+userNames+"</td><td>"+jobs+"</td><td><i class='delete_icon' onclick='remoVal();'></i></td></tr>";
		$("#handeInfo").html(html);
		$("#handleId").val(objVal);
	}
	//移除
	function remoVal(){
		$("#delFlag").remove();
		$("#handleId").val("");
	}
	function  getUserInfo(thisObj){
		var  fkBranId=$(thisObj).attr("pkBranId");
		$(".order_add_peic_hover").removeClass("order_add_peic_hover");
		$(thisObj).parent().addClass("order_add_peic_hover");
		$.ajax({
			url:"${basePath}filemanagement/customer/selectUsesJobInfo.shtml",
			dataType:"json",
			type:"post",
			async:false,
			data:{"fkBranId":fkBranId},
			error : function(XMLHttpRequest) {
	 				ajaxError(XMLHttpRequest);
	 			},
			success:function(result){
				trimJsonArray(result);
				var html="";
				$(result).each(function(id,item){
					if(id==0){
						html+='<tr><td><input type="radio" name="pkUsrId"  checked="checked"     userNames="'+item.usrName+'"  jobs="'+item.jobs+'"   value="'+item.pkUsrId+'"></td>'; 
					}else{
						html+='<tr><td><input type="radio" name="pkUsrId"     userNames="'+item.usrName+'"  jobs="'+item.jobs+'"  value="'+item.pkUsrId+'"></td>'; 
					}
					html+='<td>'+item.usrName+'</td>';
					html+='<td>'+item.jobs+'</td></tr>';
				});
				$("#showUserInfo").html(html);
			}
		});		
	}
	function getInfo(fkBranId){
		$.ajax({
			url:"${basePath}filemanagement/customer/selectUsesJobInfo.shtml",
			dataType:"json",
			type:"post",
			async:false,
			data:{"fkBranId":fkBranId},
			error : function(XMLHttpRequest) {
	 				ajaxError(XMLHttpRequest);
	 			},
			success:function(result){
				trimJsonArray(result);
				var html="";
				$(result).each(function(id,item){
					if(id==0){
						html+='<tr><td><input type="radio" name="pkUsrId"  checked="checked"    userNames="'+item.usrName+'"  jobs="'+item.jobs+'"  value="'+item.pkUsrId+'"></td>'; 
					}else{
						html+='<tr><td><input type="radio" name="pkUsrId"     userNames="'+item.usrName+'"  jobs="'+item.jobs+'" value="'+item.pkUsrId+'"></td>'; 
					}					
					html+='<td>'+item.usrName+'</td>';
					html+='<td>'+item.jobs+'</td></tr>';
				});
				$("#showUserInfo").html(html);
				$(".order_add_peic_hover").removeClass("order_add_peic_hover");
				$("#_select_"+fkBranId).parent().addClass("order_add_peic_hover");
			}
		});		
	}
	function  selectUser(){
		$('#x').window('open');
		getInfo(branId);
	}
	
	//选择会员
	function selectVip(){
		initParams();
		$("#selectVip").window('open');
	}
	//初始化参数
	function initParams() {
		$("#pageNo").val("1");
		var myform = $("#vipInfo");
		var pagebean = new PageBean(myform);
		pagebean.setTableId("showData");
		pagebean.setFootId("foot");
		pagebean.setCallback(showData);
		setPagebeanObj(pagebean); //全局化pageBean对象
		pagebean.doPage();  //执行分页
	}
	//展示数据
	function showData(result){
		trimJsonArray(result);
		$(result).each(function(index,item){
            var html="";
            if(index==0){
	            html+="<tr><td><input type='radio' name='vipId'   cusName='"+item.name+"'  checked='checked'   value='"+item.pkMemId+"' />"+item.pkMemId+"</td>";
            }else{
	            html+="<tr><td><input type='radio' name='vipId'    cusName='"+item.name+"'   value='"+item.pkMemId+"' />"+item.pkMemId+"</td>";
            }
            html+="<td>"+item.name+"</td>";
            html+="<td>"+item.sex+"</td>";
            html+="<td>"+item.age+"</td>";
            html+="<td>"+item.countryDesc+"</td>";
            if(item.isVip=="1"){
            	html+="<td>是</td>";
            }else{
            	html+="<td>否</td>";
            }
            if(item.memType=="1"){
                html+="<td>会员</td></tr>";
            }else if(item.memType=="2"){
                html+="<td>非会员</td></tr>";
            }else{ 
                html+="<td>访客</td></tr>";
            }
			$("#showData").find("tr:eq("+index+")").after(html);
		});
	}
</script>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
    			<shiro:hasPermission name="filemanagement/listVip.shtml?type=1">
    						<li><a href="${basePath}filemanagement/listVip.shtml?type=1"><i class="nav_icon_b"></i><br>会员管理</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="filemanagement/viewVistors.shtml?type=3">
            			<li><a href="${basePath}filemanagement/viewVistors.shtml?type=3"><i class="nav_icon_d"></i><br>访客管理</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="filemanagement/listViewSingelTicket.shtml?type=2">
           				<li><a href="${basePath}filemanagement/listViewSingelTicket.shtml?type=2"><i class="nav_icon_a"></i><br>非会员管理</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="parreserve/parReserveManages.shtml?indexflag=">
					<li><a href="${basePath }parreserve/parReserveManages.shtml?indexflag="><i class="nav_icon_g"></i><br>预约管理</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="filemanagement/customer/serviceList.shtml">
						<li  class="content_hover"><a href="${basePath}filemanagement/customer/serviceList.shtml"><i class="nav_icon_h"></i><br>客户服务</a></li>
    			</shiro:hasPermission>
    			<shiro:hasPermission name="crm/jumpCrm.shtml">
						<li><a href="${basePath }crm/jumpCrm.shtml"><i class="nav_icon_n"></i><br>客户关系管理</a></li>
    			</shiro:hasPermission>
			</ul>
    </div>
    <div class="content_r mt10">
        <div class="file_apply_l fixed mt50 border_r">
        <form action="${basePath}filemanagement/customer/saveApplyCustomer.shtml" id="saveService" method="post">
    	  <input type="hidden" name="applyBy" value="${userId}"/>
    	  <input type="hidden" name="fkBranId" value="${fkBranId}"/>
    	  <input type="hidden" name="status"  id="status"   value=""/>
    	   <input type="hidden" name="fkMemId"  id="fkMemId"   value=""/>
    	  <input type="hidden" name="handleId"  id="handleId"  value=""/>
    	  <input type="hidden" name="careType" value="2"/>
            <dl class="order_add_l_dl">
                <dd><label>服务请求类型：</label>申请</dd>
                <dd><label>创建人：</label><input type="text" disabled="disabled" value="${userName}" class="iput_t w200"></dd>
                <dd><label>创建时间 ：</label><input type="text" disabled="disabled" value="${createTime}" class="iput_t w200"></dd>
                <dd>
                    <label>途径：</label>
                    <ul class="ul_radio fixed">
                        <li><input type="radio" name="channel"  value="1"   checked="checked">电话</li>
                        <li><input type="radio" name="channel"  value="2">现场</li>
                        <li><input type="radio" name="channel"  value="3">邮件</li>
                    </ul>
                </dd>
                <dd><label>儿童姓名：</label><input type="text" value="" class="iput_t w100" name="cusName" id="cusName" ><input type="button" class="btn ml10" value="选择" onclick="selectVip();"><font style="color:#F00">*</font></dd>
                <dd><label>固话：</label><input type="text" value="" name="tel" class="iput_t w200" onblur="checkIsTel(this);"  title="固话号码格式，例如021-7930233,或加分机号021-7930181-0001"></dd>
                <dd><label>手机：</label><input type="text" value="" name="mobile"  id="mobile"  class="iput_t w200" onblur="checkIsMobile(this);"><font color="red">*</font></dd>
                <dd><label>备注：</label><textarea class="textare w200 h80" name="comments" id="comments"></textarea><font color="red">*</font></dd>
            </dl>
            </form>
        </div>
        <div class="file_apply_r f14 p20 mt30">
			<div class="fl file_apply_jieg ml50">
            	<ul>
                    <li><a href="#" onclick="selectUser();"><input type="button" class="btn" value="选择处理人"></a></li>
                    <li class="w600">
                    	<table class="table" id="handeInfo">
                        	
                        </table>
                    </li>
                </ul>
            </div>
        </div>
        <div class="clear"></div>
        <div class="btm_btn">
        	<dl>
                <dd><input type="button" class="btn" value="保存" onclick="saveService('1');"></dd>
                <dd><input type="button" class="btn" value="提交" onclick="saveService('2');"></dd>
                <dd><input type="button" class="btn" value="返回" onclick="window.location.href='${basePath}filemanagement/customer/serviceList.shtml'"></dd>
            </dl>
        </div>
 <div id="hide_loading">
	<div class="loading"></div>    
    <div class="loading_bg" ></div>	
</div>
        
    </div>
</div>
<!---弹出层--->
<div id="x" class="easyui-window" title="选择处理人" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:620px; height:420px; position:relative;">
	
    <div class="m10">
    	<dl class="order_add_peic fl">
            <dd style="text-indent:12px;">嘉童</dd>
            <c:forEach items="${branList}" var="item">
            	<dd><a href="#" pkBranId="${item.pkBranId}"  id="_select_${item.pkBranId}"   onclick="getUserInfo(this);" >${item.branName}</a></dd>
            </c:forEach>
        </dl>
        <div id="scrollTable" class="file_apply_m fl" style="width:440px !important; margin-top:0 !important">
            <table class="table">
                <col width="80px"></col>
                <col width="160px"></col>
                <col></col>
                <tbody>
                    <tr>
                        <th>选择</th>
                        <th>姓名</th>
                        <th>职位</th>
                    </tr>
                </tbody>
            </table>
			<div style="height:270px !important">
            <table class="table" id="selectProduct" >
				<col width="80px"></col>
                <col width="160px"></col>
                <col></col>
                <tbody id="showUserInfo">
					
                </tbody>
            </table>
            </div>
        </div>
    </div>
    
    <div class="btm_btn btm_bg">
    	<dl>
        	<dd><input type="button" class="btn" onclick="setHandleUser();" value="确定"></dd>
            <dd><input type="button" class="btn" onclick="$('#x').window('close');" value="取消"></dd>
        </dl>
    </div>
</div>
<!-- 选择会员 -->
<!---弹出层--->
<div id="selectVip" class="easyui-window" title="会员条件查询" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:800px; height:430px; position:relative;">
	<form action="${basePath}filemanagement/customer/getVipUserInfo.shtml" id="vipInfo">
    <input type="hidden" name="pageNo" id="pageNo" value="1">
    <input type="hidden" name="pageSize" value="8">
    <div class="w360_c">
    	<p class="m20">姓名/电话:<input type="text" class="iput_t w200"  name="nameOrTel"><input type="button" class="btn_l ml10" value="查询"  onclick="initParams();"></p>
    </div>
    <div class="m10">
    	<table class="table" id="showData">
           <tr>
                <th>编号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>国籍</th>
                <th>VIP</th>
                <th>类型</th>
            </tr>
      </table>
        <!---翻页-->
        <div class="page fr m10" id="foot">

        </div>
        <!----->
    </div>
    </form>
    <div class="btm_btn btm_bg">
    	<dl>
			<dd><input type="button" class="btn" onclick="getSelectVal();" value="确定"></dd>
			<dd><input type="button" class="btn" onclick="$('#selectVip').window('close')" value="返回"></dd>
        </dl>
    </div>
</div>
<!-- 转圈圈 -->

</body>
</html>